import java.util.Scanner;

public class Test {

    public String userName="ddd";
    public String passWord="www";

    public void  fun1(String userName,String passWord){
        if(!(this.userName.equals(userName))){

            throw new UserNameException("用户名错误！");
        }
        if(!(this.passWord.equals(passWord))){

            throw new PasswordException("密码异常！");
        }


    }
    public static void main(String[] args) {

        try{
            Test test =new Test();
            Scanner scanner=new Scanner(System.in);
            String username=scanner.nextLine();
            String password=scanner.nextLine();
            test.fun1(username,password);
        }catch(UserNameException o){
            o.printStackTrace();
            System.out.println("用户名异常");
        }catch(PasswordException o){
            o.printStackTrace();
            System.out.println("密码异常");
        }

    }
    public static void main2(String[] args) {

        try{
            int array[]=null;
            int[] array1=new int[4];

            System.out.println(array1[5]);
            System.out.println(array.length);

        }catch(NullPointerException e){

            e.printStackTrace();
            System.out.println("NullPointerException空指针异常！");

        }catch(ArrayIndexOutOfBoundsException e){

            System.out.println("ArrayIndexOutOfBoundsException 数组越界异常！");
        }
        catch (RuntimeException e){

            System.out.println("捕获异常！");
        }
        finally{
            System.out.println("finally被执行了!");
        }
    }

    public static void func()throws NullPointerException{
        int array[]=null;
        System.out.println(array.length);
    }
    public static void main1(String[] args) {
    try{//可能会发生的异常！
            func();
        }catch(NullPointerException e){//捕获的·异常

            e.printStackTrace();
            System.out.println("处理NullPointerException异常！");
        }



    }
}
